﻿using Cofe = Cofe.Core;
using Cofe.Core.Interfaces;
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Cofe.Core.Service;

namespace Cofe.Core.Property
{
    public class CofeActionProvider : TransformingPropertyProviderBase
    {

        #region Factory
        [Export(typeof(ICofeService))]
        [ServicePriority(ServicePriorityAttribute.DefaultPriority_COFE)]
        public class Factory : ISecondaryPropertyProviderFactory
        {
            public IEnumerable<IPropertyProvider> GetSecoondaryPropertyProviders(IPropertyHost propertyHost)
            {
                if (!(propertyHost.SecondaryPropertyProviders.Any((p) => p is CofeActionProvider)))
                    yield return new CofeActionProvider(propertyHost);
            }

            private IServiceLocater _serviceLocater = null;
            public IServiceLocater ServiceLocater
            {
                get { return _serviceLocater ?? CofeServices.ServiceLocater; }
                set { _serviceLocater = value; }
            }
        }
        #endregion

        #region Constructor

        private static IPropertyProvider[] initPPArray(IPropertyProvider primaryPropertyProvider,
            IPropertyProvider[] secondaryPropertyProviders)
        {
            var retVal = new List<IPropertyProvider>(secondaryPropertyProviders);
            retVal.Add(primaryPropertyProvider);
            return retVal.ToArray();
        }

        public CofeActionProvider(IPropertyHost propertyHost)
            : base(propertyHost,
            new IPropertyDefinitions[] { Core.PropertyDefinitions.CofeDefinitions })
        {
            //registerTransformAction<bool, bool>(CofeProperties.DeleteCoreAsync, CofeProperties.DeleteAsync);
            //registerTransformAction<bool, bool>(CofeProperties.OpenReadCoreAsync, CofeProperties.OpenReadAsync);
            //registerTransformAction<bool, bool>(CofeProperties.OpenWriteCoreAsync, CofeProperties.OpenWriteAsync);
            //registerTransformAction<bool, bool>(CofeDirectoryProperties.CreateCore, CofeProperties.Create);            
        }

        #endregion

    }
}
